import requests,os,shutil
from lxml import etree

cookies = input("你是谁？————请输入账号信息Cookies：")
urls = input("你要干啥？————请输入ppt列表页面链接：")

headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.44',
    'Cookie': str(cookies),
}
def get_datas(url):
    response = requests.get(url,headers=headers)
    return response

def parse(res):
    html = etree.HTML(res.text)
    titles = html.xpath('//td[@class="common indentten"]/a/text()')
    details_urls = ['http://eol.shzu.edu.cn/meol/analytics/resPdfShow.do?resId='+i[50::] for i in html.xpath('//td[@class="common indentten"]/a/@href')]
    return titles, details_urls

def down_pdf(name,datas):
    print(f'正在下载{name}pdf')
    with open(f'./Download/{name}.pdf', 'wb+') as f:
        f.write(datas.content)

if __name__ == "__main__":
    pdf_info = parse(get_datas(urls))
    if os.path.exists('Download/'):shutil.rmtree('./Download/')
    os.makedirs('Download/')
    for title,link in zip(pdf_info[0],pdf_info[1]):
        down_pdf(title,get_datas(link))